<?php

// +----------------------------------------------------------------------
// | Banner 模型
// +----------------------------------------------------------------------
// | @author fancsen
// +----------------------------------------------------------------------

namespace app\api\model;

use app\api\model\BaseModel;

class Banner extends BaseModel 
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'banner';
    //自动时间戳
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    //protected $createTime = 'create_at';
    protected $updateTime = 'update_time';
    protected $deleteTime = 'delete_time';
    //隐藏字段
    protected $hidden = ['delete_time','update_time'];
    //关联banner_itme
    public function items()
	{
		return $this->hasMany('BannerItem','banner_id','id');
	}
    /**
    * 通过id获取banner
    * @param number $id 主键id
    * @return obeject
    */
    public static function getBannerById($id)
    {
        $banner = self::with(['items','items.img'])->find($id);

        return $banner;
    }
}